import 'package:flutter/material.dart';
import 'package:shenfuhui/config/config.dart';
import 'package:webview_flutter/webview_flutter.dart';

///
/// webview
///
class WebViewPage extends StatefulWidget {
  String pageTitle;

  WebViewPage({Key? key, this.pageTitle = ""}) : super(key: key);

  @override
  State<WebViewPage> createState() => _WebViewPageState();
}

class _WebViewPageState extends State<WebViewPage> {
  late WebViewController controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller = WebViewController();
    controller.setJavaScriptMode(JavaScriptMode.unrestricted);
    controller.setNavigationDelegate(
      NavigationDelegate(onPageFinished: (url) async {}),
    );
    controller.loadRequest(Uri.parse('https://m.hao123.com/'));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Config.colorBg2,
        appBar: AppBar(
          title: Text(widget.pageTitle),
          centerTitle: true,
        ),
        body: SizedBox(
          width: double.infinity,
          height: double.infinity,
          child: WebViewWidget(
            controller: controller,
          ),
        ));
  }
}
